package com.hsylient.translator.gpt;

import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;

import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class SelectMaxLength {

    private static final String EXCEL_LOCATION = "C:\\Users\\Hsylient\\Desktop\\Nove-X翻译.xlsx";

    // 第几个sheet页，从0开始计数
    private static final Integer SHEET_INDEX = 0;
    private static final ExcelWriter writer = ExcelUtil.getWriter(EXCEL_LOCATION, "前端翻译");
    private static final ExcelReader reader = ExcelUtil.getReader(EXCEL_LOCATION, SHEET_INDEX);


    public static void main(String[] args) {
        // 忽略空白行
        reader.setIgnoreEmptyRow(Boolean.TRUE);
        // 读出所有的行
        List<Map<String, Object>> langaugeList = reader.readAll();

        for (int i = 41; i < langaugeList.size(); i++) {
            String fa = Optional.ofNullable((String) langaugeList.get(i).get("法语")).orElse("");
            String eyu = Optional.ofNullable((String) langaugeList.get(i).get("俄语（Русский）")).orElse("");
            String wkly = Optional.ofNullable((String) langaugeList.get(i).get("乌克兰语（Українська）")).orElse("");
            String yny = Optional.ofNullable((String) langaugeList.get(i).get("越南语（Tiếng Việt）")).orElse("");
            String xbyy = Optional.ofNullable((String) langaugeList.get(i).get("西班牙语（español）")).orElse("");

            List<String> collect = Stream.of(fa, eyu, wkly, yny, xbyy)
                    .sorted(Comparator.comparingInt(String::length).reversed())
                    .collect(Collectors.toList());

            if (collect.get(0).equals(fa) && collect.get(0).trim().length() > collect.get(1).trim().length()) {
                writer.writeCellValue(11, i + 1, 1);
            }
            System.out.println("第" + i + "行处理完了。。。");
        }
        writer.flush();
    }
}
